<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title></title> 

</head>
<jsp:include page="../default.jsp" />
<body>
	<div class="mini-fit">
		<div id="form" align="center">
			<input name="id" class="mini-hidden"/>		
			<table align="center" width="100%" border="0" cellpadding="0" cellspacing="0">
				<tr height="30px">
				   <td align="right">代码：</td>
				   <td>
				       <input name="code" class="mini-textbox" vtype="letterAndNumber;maxLength:20;" required="true"/>
				   </td>
				   <td align="right">名称：</td>
				   <td>
				       <input name="name" class="mini-textbox" vtype="maxLength:25;" required="true"/>
				   </td>
				</tr>
			</table>			
		</div>
	</div>
	<div class="mini-toolbar" style="text-align: center; border-bottom:0;border-left:0;border-right:0;">		
		<a class="mini-button" iconCls="icon-save" onclick="save()" id="saveBtn">保存</a>
		<a class="mini-button" iconCls="icon-close" onclick="CommonUtil.prototype.closeWindow()">关闭</a>
	</div>
    <script type="text/javascript">
    	mini.parse();
    	var form = new mini.Form("#form");
    	
    	function setData(data) {
            data = mini.clone(data);
    		window.action = data.action;   		
            if(data.action == "view"){
            	form.setEnabled(false);
            	$("#saveBtn").hide();
            }
            if (data.action == "edit" || data.action == "view") {
            	CommonUtil.prototype.mask();
                $.ajax({
                    url: "${pageContext.request.contextPath}/auth/role/load.do?action=" + window.action,
                    data : {id: data.id},
                    type : "POST",
					dataType : "json",
                    success: function (data, textStatus, jqXHR) {
                    	CommonUtil.prototype.unmask();
                    	if(data.success){
                    		form.setData(data.data);
                        	form.setChanged(false);
                    	}else{
                    		form.setEnabled(false);
            				$("#saveBtn").hide();
                    	}                       
                    }
                });
            }
        }
    	
    	function save(){
    		form.validate();
            if (form.isValid() == false) return;
            CommonUtil.prototype.mask();
            $.ajax({
				url : "${pageContext.request.contextPath}/auth/role/save.do?action=" + window.action,
				data : form.getData(true),
				type : "POST",
				dataType : "json",
				success : function(data, textStatus, jqXHR) {
					CommonUtil.prototype.unmask();
					if(data.success){
						mini.alert("保存成功", "提醒", function(){
							CommonUtil.prototype.closeWindow('ignore');
						});
					}				
				}
			});	
    	}   	
	</script>
  </body>
</html>
